Calculates the characteristic polynomial of the matrix M with respect to the variable.